package com.coldchain.admin.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.coldchain.admin.user.entity.Role;
import com.coldchain.admin.user.mapper.RoleMapper;
import com.coldchain.admin.user.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fangliai.core.context.BaseContextHandler;
import com.fangliai.core.entitiy.SystemModelEnum;
import com.fangliai.core.exception.BaseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色 服务实现类
 * </p>
 *
 * @author fangliai
 * @since 2018-09-11
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    private static final Logger log= LoggerFactory.getLogger(RoleServiceImpl.class);
    @Override
    public List<Role> findRoleByList() throws BaseException {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq(true,"sysmodel",BaseContextHandler.getSysModl());
        if(!BaseContextHandler.getSysModl().equals(SystemModelEnum.ADMIN.name())){
            wrapper. eq("targetId",BaseContextHandler.getCysIdOrCommpanyId());
        }

        try {
            return super.list(wrapper);
        }catch (Exception e){
            log.error("查询角色失败 error{}",e.getMessage());
            throw  new BaseException("服务器异常");
        }

    }


}
